function WebGLCrown(gl)
{
    var crownShader = new Shader(
        gl,
		"const vec4 lightpos = vec4(0.0, 10.0, 0.0, 1.0); "+
		"attribute vec3 position; attribute vec3 normal; "+
		"varying vec3 nor; varying vec4 pos; varying vec4 lightViewSpace; "+
		"uniform mat4 projection; uniform mat4 view; uniform mat4 model; "+
		"void main() {"+
		"   pos = view * model * vec4(position, 1);"+
		"   gl_Position = projection * pos;"+
		"   nor = normalize((view * model * vec4(normal, 0)).xyz);"+
		"   lightViewSpace = view * lightpos;"+
		"}"
		,
        "varying vec3 nor; varying vec4 pos; "+
		"varying vec4 lightViewSpace;" +
		"uniform vec4 color; "+
		"const vec3 attenuation  = vec3(1.0, 0.005, 0.00025);"+
		"void main() {" +
		"   vec4 pos2light = lightViewSpace - pos;" + 
		"   float dist = length(pos2light);" + 
		"   vec4 light = normalize(pos2light);" +
		"   float attfactor = 1.0 / (attenuation.x + attenuation.y * dist + attenuation.z * dist * dist);"+
		"   float diffuse = attfactor * max(0.0, dot(nor, light.xyz));"+
		"   float specular = attfactor * pow(max(0.0, dot(-reflect(light.xyz, nor), normalize(-pos).xyz)), 2.0);"+
		"   gl_FragColor = vec4(((0.6 + diffuse) * color.xyz + specular * vec3(1.0, 1.0, 1.0)), 1.0);"+
	    "}");        
	
	// Initialize buffers
	var vertexData = new WebGLFloatArray([
		// Left face        
		-1.0, 1.0, 1.0,	 -1.0, 0.0, 0.0,
		-1.0, -1.0, 1.0, 	 -1.0, 0.0, 0.0,
		-1.0, -1.0, -1.0,	 -1.0, 0.0, 0.0,	
		-1.0, 1.0, -1.0,	 -1.0, 0.0, 0.0,	
		// Right face       
		1.0, 1.0, -1.0,	 1.0, 0.0, 0.0,		
		1.0, -1.0, -1.0,	 1.0, 0.0, 0.0,			
		1.0, -1.0, 1.0,	 1.0, 0.0, 0.0,				
		1.0, 1.0, 1.0,	 1.0, 0.0, 0.0,				
		// Bottom face      
		-1.0, -1.0, -1.0,   0.0, -1.0, 0.0,
		-1.0, -1.0, 1.0,   0.0, -1.0, 0.0,	
		1.0, -1.0, 1.0,	   0.0, -1.0, 0.0,	
		1.0, -1.0, -1.0,   0.0, -1.0, 0.0,	
		// Top face         
		-1.0, 1.0, 1.0,   0.0, 1.0, 0.0,
		-1.0, 1.0, -1.0,   0.0, 1.0, 0.0,	
		1.0, 1.0, -1.0,   0.0, 1.0, 0.0,		
		1.0, 1.0, 1.0,   0.0, 1.0, 0.0,		
		// Near face        
		-1.0, 1.0, -1.0,   0.0, 0.0, -1.0,	
		-1.0, -1.0, -1.0,   0.0, 0.0, -1.0,		
		1.0, -1.0, -1.0,   0.0, 0.0, -1.0,		
		1.0, 1.0, -1.0,   0.0, 0.0, -1.0,			
		// Far face         
		1.0, 1.0, 1.0,   0.0, 0.0, 1.0,			
		1.0, -1.0, 1.0,   0.0, 0.0, 1.0,			
		-1.0, -1.0, 1.0,   0.0, 0.0, 1.0,		
		-1.0, 1.0, 1.0,   0.0, 0.0, 1.0	
	]);

	var indexData = new WebGLUnsignedShortArray([
		// Lower left triangle	Upper right triangle
		// Top left, bottom left, bottom right     top left, bottom right, top right
		// Left face
		0, 1, 2,				0, 2, 3,
		// Right face
		4, 5, 6,				4, 6, 7,
		// Bottom face
		8, 9, 10,				8, 10, 11,
		// Top Face
		12, 13, 14,				12, 14, 15,
		// Near Face
		16, 17, 18,				16, 18, 19,
		// Far face
		20, 21, 22,				20, 22, 23,
	]);

	vbo = gl.createBuffer();
	checkWebGLError(gl);
	gl.bindBuffer(gl.ARRAY_BUFFER, vbo);
	checkWebGLError(gl);
	gl.bufferData(gl.ARRAY_BUFFER, vertexData, gl.STATIC_DRAW);
	checkWebGLError(gl);

	ibo = gl.createBuffer();
	checkWebGLError(gl);
	gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, ibo);
	checkWebGLError(gl);
	gl.bufferData(gl.ELEMENT_ARRAY_BUFFER, indexData, gl.STATIC_DRAW);
	checkWebGLError(gl);
	
	this.draw = function(projection, view, xform, color)
	{
		gl.useProgram(crownShader.program);
		checkWebGLError(gl);
		
		var projLoc = gl.getUniformLocation(crownShader.program, "projection");
		checkWebGLError(gl);
		gl.uniformMatrix4fv(projLoc, true, projection);	
		checkWebGLError(gl);
		
		var viewLoc = gl.getUniformLocation(crownShader.program, "view");
		gl.uniformMatrix4fv(viewLoc, true, view);
		checkWebGLError(gl);
		
		var modelLoc = gl.getUniformLocation(crownShader.program, "model");
		gl.uniformMatrix4fv(modelLoc, true, xform);
		checkWebGLError(gl);

		var colorLoc = gl.getUniformLocation(crownShader.program, "color")
		checkWebGLError(gl);
		gl.uniform4f(colorLoc, color[0], color[1], color[2], color[3]);
		
		var positionLoc = gl.getAttribLocation(crownShader.program, "position");
		checkWebGLError(gl);
		var normalLoc = gl.getAttribLocation(crownShader.program, "normal");
		checkWebGLError(gl);

		gl.bindBuffer(gl.ARRAY_BUFFER, vbo);
		checkWebGLError(gl);
        gl.vertexAttribPointer(positionLoc, 3, gl.FLOAT, gl.FALSE, 24, 0)
		checkWebGLError(gl);
        gl.vertexAttribPointer(normalLoc, 3, gl.FLOAT, gl.FALSE, 24, 12)
		checkWebGLError(gl);
        gl.enableVertexAttribArray(positionLoc);
		checkWebGLError(gl);
        gl.enableVertexAttribArray(normalLoc);
		checkWebGLError(gl);
		
		gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, ibo);
		checkWebGLError(gl);
		gl.drawElements(gl.TRIANGLES, 36, gl.UNSIGNED_SHORT, 0);
		checkWebGLError(gl);
        
		gl.disableVertexAttribArray(positionLoc);
		checkWebGLError(gl);
		gl.disableVertexAttribArray(normalLoc);
		checkWebGLError(gl);
	}    
}

